package com.le.dub.controller;

import com.le.dub.common.Response;
import com.le.dub.conf.UserUtil;
import com.le.dub.mobile.DubRecord;
import com.le.dub.mobile.bo.TextToSpeechBO;
import com.le.dub.service.IAppVoiceService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author guole
 * @created 2024/10/5
 */
@RestController
@RequestMapping("/app/voice")
public class AppVoiceController {
    @Resource
    private IAppVoiceService appVoiceService;


    /**
     * 提交语音生成任务
     *
     * @return Ajaxresult转换结果
     */
    @RequestMapping(value = "/submitVoice")
    public Response submitVoice(HttpServletRequest request, @RequestBody TextToSpeechBO speechBO) {
        Long userId = UserUtil.getUserId(request);
        speechBO.setUserId(userId);
      DubRecord dubRecord=  appVoiceService.submitVoice(speechBO);
        return Response.success(dubRecord);

    }
    /**
     * 根据id查询语音生成记录
     *
     * @return Ajaxresult转换结果
     */
    @GetMapping(value = "/dubRecordById")
    public Response  dubRecordById( @RequestParam Long recordId) {
       DubRecord dubRecord= appVoiceService.dubRecordById(recordId);
        return Response.success(dubRecord);

    }
    /**
     * 根据用户id查询语音生成记录
     *
     * @return Ajaxresult转换结果
     */
    @GetMapping(value = "/dubRecordListByUser")
    public Response  dubRecordListByUser(HttpServletRequest request) {
       Long userId= UserUtil.getUserId(request);
        List<DubRecord> dubRecordList= appVoiceService.dubRecordListByUser(userId);
        return Response.success(dubRecordList);

    }

}
